﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using SCO.BE;
using SCO.DAO.Interfaces;
using System.Configuration;
namespace SCO.DAO.SqlDataAdapter
{
    public class ListasDAO : IListasDAO
    {
        string cadenaConexion = string.Empty;
        public ListasDAO() {
            this.cadenaConexion = ConfigurationManager.ConnectionStrings["CNX"].ConnectionString.ToString();
        }

        public List<comboBE> listaEmpresa()
        {
            comboBE objeto;
            List<comboBE> lista = new List<comboBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion)) {
                    using (SqlCommand oCmd = new SqlCommand("USP_LISTAR_EMPRESA", oCn))
                    {
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read()) {
                                objeto = new comboBE();
                                objeto.CODIGO = reader.GetInt32(reader.GetOrdinal("CODIGO"));
                                objeto.DESCRIPCION = reader.GetString(reader.GetOrdinal("DESCRIPCION"));
                                lista.Add(objeto);
                            }
                            return lista;
                        }
                        else {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<comboBE> listaOcupacion()
        {
            comboBE objeto;
            List<comboBE> lista = new List<comboBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion))
                {
                    using (SqlCommand oCmd = new SqlCommand("USP_LISTAR_OCUPACION", oCn))
                    {
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                objeto = new comboBE();
                                objeto.CODIGO = reader.GetInt32(reader.GetOrdinal("CODIGO"));
                                objeto.DESCRIPCION = reader.GetString(reader.GetOrdinal("DESCRIPCION"));
                                lista.Add(objeto);
                            }
                            return lista;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<comboBE> listaDistrito()
        {
            comboBE objeto;
            List<comboBE> lista = new List<comboBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion))
                {
                    using (SqlCommand oCmd = new SqlCommand("USP_LISTAR_DISTRITOS", oCn))
                    {
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                objeto = new comboBE();
                                objeto.CODIGO = reader.GetInt32(reader.GetOrdinal("CODIGO"));
                                objeto.DESCRIPCION = reader.GetString(reader.GetOrdinal("DESCRIPCION"));
                                lista.Add(objeto);
                            }
                            return lista;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }


        public List<comboBE> listaDoctor()
        {
            comboBE objeto;
            List<comboBE> lista = new List<comboBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion))
                {
                    using (SqlCommand oCmd = new SqlCommand("USP_LISTAR_DOCTOR", oCn))
                    {
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                objeto = new comboBE();
                                objeto.CODIGO = reader.GetInt32(reader.GetOrdinal("CODDOC"));
                                objeto.DESCRIPCION = reader.GetString(reader.GetOrdinal("NOMDOC"));
                                lista.Add(objeto);
                            }
                            return lista;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<comboBE> listaLaboratorio()
        {
            comboBE objeto;
            List<comboBE> lista = new List<comboBE>();
            try
            {
                using (SqlConnection oCn = new SqlConnection(this.cadenaConexion))
                {
                    using (SqlCommand oCmd = new SqlCommand("USP_LISTAR_LABORATORIO", oCn))
                    {
                        oCn.Open();
                        SqlDataReader reader = oCmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                objeto = new comboBE();
                                objeto.CODIGO = reader.GetInt32(reader.GetOrdinal("CODLAB"));
                                objeto.DESCRIPCION = reader.GetString(reader.GetOrdinal("DESLAB"));
                                lista.Add(objeto);
                            }
                            return lista;
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
